package com.neteast.androidclient.newscenter.util;

import com.neteast.androidclient.newscenter.Global;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class ConfigUtil {
	/**
	 * 设置清空消息是否自动关闭消息列表
	 * @param context
	 * @param autoClose
	 */
	public static void setAutoClose(Context context,int userID,boolean autoClose) {
		SharedPreferences sp = context.getSharedPreferences(userID+"", Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putBoolean(Global.PREFERENCE_CONFIG_AUTO_CLOSE, autoClose);
		edit.commit();
	}
	/**
	 * 获取清空消息是否自动关闭消息列表
	 * @param context
	 * @return
	 */
	public static boolean getAutoClose(Context context,int userId){
		SharedPreferences sp = context.getSharedPreferences(userId+"", Context.MODE_PRIVATE);
		return sp.getBoolean(Global.PREFERENCE_CONFIG_AUTO_CLOSE, false);
	}
	/**
	 * 设置广播消息是否提示
	 * @param context
	 * @param isNotify
	 */
	public static void setCloseBroadcastNotify(Context context,int userId,boolean isNotify) {
		SharedPreferences sp = context.getSharedPreferences(userId+"", Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putBoolean(Global.PREFERENCE_CONFIG_BROADCAST_NOTIFY, isNotify);
		edit.commit();
	}
	/**
	 * 获取广播消息是否数字提示
	 * @param context
	 * @return
	 */
	public static boolean getCloseBroadcastNotify(Context context,int userId){
		SharedPreferences sp = context.getSharedPreferences(userId+"", Context.MODE_PRIVATE);
		return sp.getBoolean(Global.PREFERENCE_CONFIG_BROADCAST_NOTIFY, false);
	}
	/**
	 * 设置删除消息时是否进一步弹出对话框确认。
	 * @param context
	 * @param isConfirm
	 */
	public static void setDeleteConfirm(Context context,int userId,boolean isConfirm) {
		SharedPreferences sp = context.getSharedPreferences(userId+"", Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putBoolean(Global.PREFERENCE_CONFIG_DELETE_CONFIRM, isConfirm);
		edit.commit();
	}
	/**
	 * 获取删除消息时是否进一步弹出对话框确认
	 * @param context
	 * @return
	 */
	public static boolean getDeleteConfirm(Context context,int userId){
		SharedPreferences sp = context.getSharedPreferences(userId+"", Context.MODE_PRIVATE);
		return sp.getBoolean(Global.PREFERENCE_CONFIG_DELETE_CONFIRM, false);
	}
	/**
	 * 设置bootstrap服务器的ip
	 * @param context
	 * @param ip
	 */
	public static void setBootStrapIp(Context context,String ip) {
		SharedPreferences sp = context.getSharedPreferences(Global.PREFERENCE_CONFIG_FILE, Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putString(Global.PREFERENCE_BOOTSTRAP_IP, ip);
		edit.commit();
	}
	/**
	 * 获取bootStrap服务器的ip
	 * @param context
	 * @return
	 */
	public static String getBootStrapIp(Context context){
		SharedPreferences sp = context.getSharedPreferences(Global.PREFERENCE_CONFIG_FILE, Context.MODE_PRIVATE);
		return sp.getString(Global.PREFERENCE_BOOTSTRAP_IP, "218.108.168.46");
	}
	/**
	 * 设置bootstrap服务器的port
	 * @param context
	 * @param ip
	 */
	public static void setBootStrapPort(Context context,int port) {
		SharedPreferences sp = context.getSharedPreferences(Global.PREFERENCE_CONFIG_FILE, Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putInt(Global.PREFERENCE_BOOTSTRAP_PORT, port);
		edit.commit();
	}
	/**
	 * 获取bootStrap服务器的port
	 * @param context
	 * @return
	 */
	public static int getBootStrapPort(Context context){
		SharedPreferences sp = context.getSharedPreferences(Global.PREFERENCE_CONFIG_FILE, Context.MODE_PRIVATE);
		return sp.getInt(Global.PREFERENCE_BOOTSTRAP_PORT, 8087);
	}
}
